<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Gegenbauer Polynomials</title>
<link rel="stylesheet" href="../../math.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../index.html" title="Math Toolkit 4.2.1">
<link rel="up" href="../sf_poly.html" title="Polynomials">
<link rel="prev" href="cardinal_b_splines.html" title="Cardinal B-splines">
<link rel="next" href="jacobi.html" title="Jacobi Polynomials">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="cardinal_b_splines.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../sf_poly.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="jacobi.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="math_toolkit.sf_poly.gegenbauer"></a><a class="link" href="gegenbauer.html" title="Gegenbauer Polynomials">Gegenbauer Polynomials</a>
</h3></div></div></div>
<h5>
<a name="math_toolkit.sf_poly.gegenbauer.h0"></a>
        <span class="phrase"><a name="math_toolkit.sf_poly.gegenbauer.synopsis"></a></span><a class="link" href="gegenbauer.html#math_toolkit.sf_poly.gegenbauer.synopsis">Synopsis</a>
      </h5>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">special_functions</span><span class="special">/</span><span class="identifier">gegenbauer</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
</pre>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">math</span><span class="special">{</span>

<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Real</span><span class="special">&gt;</span>
<span class="identifier">Real</span> <span class="identifier">gegenbauer</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">n</span><span class="special">,</span> <span class="identifier">Real</span> <span class="identifier">lambda</span><span class="special">,</span> <span class="identifier">Real</span> <span class="identifier">x</span><span class="special">);</span>

<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Real</span><span class="special">&gt;</span>
<span class="identifier">Real</span> <span class="identifier">gegenbauer_prime</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">n</span><span class="special">,</span> <span class="identifier">Real</span> <span class="identifier">lambda</span><span class="special">,</span> <span class="identifier">Real</span> <span class="identifier">x</span><span class="special">);</span>

<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Real</span><span class="special">&gt;</span>
<span class="identifier">Real</span> <span class="identifier">gegenbauer_derivative</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">n</span><span class="special">,</span> <span class="identifier">Real</span> <span class="identifier">lambda</span><span class="special">,</span> <span class="identifier">Real</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="identifier">k</span><span class="special">);</span>

<span class="special">}}</span> <span class="comment">// namespaces</span>
</pre>
<p>
        Gegenbauer polynomials are a family of orthogonal polynomials.
      </p>
<p>
        A basic usage is as follows:
      </p>
<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">gegenbauer</span><span class="special">;</span>
<span class="keyword">double</span> <span class="identifier">x</span> <span class="special">=</span> <span class="number">0.5</span><span class="special">;</span>
<span class="keyword">double</span> <span class="identifier">lambda</span> <span class="special">=</span> <span class="number">0.5</span><span class="special">;</span>
<span class="keyword">unsigned</span> <span class="identifier">n</span> <span class="special">=</span> <span class="number">3</span><span class="special">;</span>
<span class="keyword">double</span> <span class="identifier">y</span> <span class="special">=</span> <span class="identifier">gegenbauer</span><span class="special">(</span><span class="identifier">n</span><span class="special">,</span> <span class="identifier">lambda</span><span class="special">,</span> <span class="identifier">x</span><span class="special">);</span>
</pre>
<p>
        All derivatives of the Gegenbauer polynomials are available. The <span class="emphasis"><em>k</em></span>-th
        derivative of the <span class="emphasis"><em>n</em></span>-th Gegenbauer polynomial is given
        by
      </p>
<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">gegenbauer_derivative</span><span class="special">;</span>
<span class="keyword">double</span> <span class="identifier">x</span> <span class="special">=</span> <span class="number">0.5</span><span class="special">;</span>
<span class="keyword">double</span> <span class="identifier">lambda</span> <span class="special">=</span> <span class="number">0.5</span><span class="special">;</span>
<span class="keyword">unsigned</span> <span class="identifier">n</span> <span class="special">=</span> <span class="number">3</span><span class="special">;</span>
<span class="keyword">unsigned</span> <span class="identifier">k</span> <span class="special">=</span> <span class="number">2</span><span class="special">;</span>
<span class="keyword">double</span> <span class="identifier">y</span> <span class="special">=</span> <span class="identifier">gegenbauer_derivative</span><span class="special">(</span><span class="identifier">n</span><span class="special">,</span> <span class="identifier">lambda</span><span class="special">,</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">k</span><span class="special">);</span>
</pre>
<p>
        For consistency with the rest of the library, <code class="computeroutput"><span class="identifier">gegenbauer_prime</span></code>
        is provided which simply returns <code class="computeroutput"><span class="identifier">gegenbauer_derivative</span><span class="special">(</span><span class="identifier">n</span><span class="special">,</span>
        <span class="identifier">lambda</span><span class="special">,</span>
        <span class="identifier">x</span><span class="special">,</span><span class="number">1</span> <span class="special">)</span></code>.
      </p>
<p>
        <span class="inlinemediaobject"><object type="image/svg+xml" data="../../../graphs/gegenbauer.svg"></object></span>
      </p>
<h4>
<a name="math_toolkit.sf_poly.gegenbauer.h1"></a>
        <span class="phrase"><a name="math_toolkit.sf_poly.gegenbauer.implementation"></a></span><a class="link" href="gegenbauer.html#math_toolkit.sf_poly.gegenbauer.implementation">Implementation</a>
      </h4>
<p>
        The implementation uses the 3-term recurrence for the Gegenbauer polynomials,
        rising.
      </p>
<h4>
<a name="math_toolkit.sf_poly.gegenbauer.h2"></a>
        <span class="phrase"><a name="math_toolkit.sf_poly.gegenbauer.performance"></a></span><a class="link" href="gegenbauer.html#math_toolkit.sf_poly.gegenbauer.performance">Performance</a>
      </h4>
<p>
        Double precision timing on a consumer x86 laptop is shown below. Included
        is the time to generate a random number argument in the interval [-1, 1]
        (which takes 11.5ns).
      </p>
<pre class="programlisting"><span class="identifier">Run</span> <span class="identifier">on</span> <span class="special">(</span><span class="number">16</span> <span class="identifier">X</span> <span class="number">4300</span> <span class="identifier">MHz</span> <span class="identifier">CPU</span> <span class="identifier">s</span><span class="special">)</span>
<span class="identifier">CPU</span> <span class="identifier">Caches</span><span class="special">:</span>
  <span class="identifier">L1</span> <span class="identifier">Data</span> <span class="number">32</span><span class="identifier">K</span> <span class="special">(</span><span class="identifier">x8</span><span class="special">)</span>
  <span class="identifier">L1</span> <span class="identifier">Instruction</span> <span class="number">32</span><span class="identifier">K</span> <span class="special">(</span><span class="identifier">x8</span><span class="special">)</span>
  <span class="identifier">L2</span> <span class="identifier">Unified</span> <span class="number">1024</span><span class="identifier">K</span> <span class="special">(</span><span class="identifier">x8</span><span class="special">)</span>
  <span class="identifier">L3</span> <span class="identifier">Unified</span> <span class="number">11264</span><span class="identifier">K</span> <span class="special">(</span><span class="identifier">x1</span><span class="special">)</span>
<span class="identifier">Load</span> <span class="identifier">Average</span><span class="special">:</span> <span class="number">0.21</span><span class="special">,</span> <span class="number">0.33</span><span class="special">,</span> <span class="number">0.29</span>
<span class="special">-----------------------------------------</span>
<span class="identifier">Benchmark</span>                            <span class="identifier">Time</span>
<span class="special">-----------------------------------------</span>
<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">1</span>              <span class="number">12.5</span> <span class="identifier">ns</span>
<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">2</span>              <span class="number">13.5</span> <span class="identifier">ns</span>
<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">3</span>              <span class="number">14.6</span> <span class="identifier">ns</span>
<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">4</span>              <span class="number">16.0</span> <span class="identifier">ns</span>
<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">5</span>              <span class="number">17.5</span> <span class="identifier">ns</span>
<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">6</span>              <span class="number">19.2</span> <span class="identifier">ns</span>
<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">7</span>              <span class="number">20.7</span> <span class="identifier">ns</span>
<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">8</span>              <span class="number">22.2</span> <span class="identifier">ns</span>
<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">9</span>              <span class="number">23.6</span> <span class="identifier">ns</span>
<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">10</span>             <span class="number">25.2</span> <span class="identifier">ns</span>
<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">11</span>             <span class="number">26.9</span> <span class="identifier">ns</span>
<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">12</span>             <span class="number">28.7</span> <span class="identifier">ns</span>
<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">13</span>             <span class="number">30.5</span> <span class="identifier">ns</span>
<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">14</span>             <span class="number">32.5</span> <span class="identifier">ns</span>
<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">15</span>             <span class="number">34.3</span> <span class="identifier">ns</span>
<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">16</span>             <span class="number">36.3</span> <span class="identifier">ns</span>
<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">17</span>             <span class="number">38.0</span> <span class="identifier">ns</span>
<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">18</span>             <span class="number">39.9</span> <span class="identifier">ns</span>
<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">19</span>             <span class="number">41.8</span> <span class="identifier">ns</span>
<span class="identifier">Gegenbauer</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;/</span><span class="number">20</span>             <span class="number">43.8</span> <span class="identifier">ns</span>
<span class="identifier">UniformReal</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span>               <span class="number">11.5</span> <span class="identifier">ns</span>
</pre>
<h4>
<a name="math_toolkit.sf_poly.gegenbauer.h3"></a>
        <span class="phrase"><a name="math_toolkit.sf_poly.gegenbauer.accuracy"></a></span><a class="link" href="gegenbauer.html#math_toolkit.sf_poly.gegenbauer.accuracy">Accuracy</a>
      </h4>
<p>
        Some representative ULP plots are shown below. The relative accuracy cannot
        be controlled at the roots of the polynomial, as is to be expected.
      </p>
<p>
        <span class="inlinemediaobject"><object type="image/svg+xml" data="../../../graphs/gegenbauer_ulp_3.svg"></object></span> <span class="inlinemediaobject"><object type="image/svg+xml" data="../../../graphs/gegenbauer_ulp_5.svg"></object></span>
        <span class="inlinemediaobject"><object type="image/svg+xml" data="../../../graphs/gegenbauer_ulp_9.svg"></object></span>
      </p>
<h4>
<a name="math_toolkit.sf_poly.gegenbauer.h4"></a>
        <span class="phrase"><a name="math_toolkit.sf_poly.gegenbauer.caveats"></a></span><a class="link" href="gegenbauer.html#math_toolkit.sf_poly.gegenbauer.caveats">Caveats</a>
      </h4>
<p>
        Some programs define the Gegenbauer polynomial with λ = 0 via renormalization
        (which makes them Chebyshev polynomials). We do not follow this convention:
        In this case, only the zeroth Gegenbauer polynomial is nonzero.
      </p>
</div>
<div class="copyright-footer">Copyright © 2006-2021 Nikhar Agrawal, Anton Bikineev, Matthew Borland,
      Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert Holin, Bruno
      Lalande, John Maddock, Evan Miller, Jeremy Murphy, Matthew Pulver, Johan Råde,
      Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg, Daryle
      Walker and Xiaogang Zhang<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="cardinal_b_splines.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../sf_poly.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="jacobi.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
